#include "Date.h"
#include <iostream>
#include <cstdlib>
using namespace std;

 namespace 
{
	constexpr int DaysBeforeMonth[] = { 0,31,59,90,120,151,181,212,243,273,304,334,365 };
}

Date::Date(int yy, int mm, int dd):year(yy),month(mm),day(dd)
{
	if (day<=0||day>getMaxDay())
	{
		cout << "Invalid Date:";
		show();
		cout << endl;
		exit(1);  // NOLINT(concurrency-mt-unsafe)
	}
	int y = year - 1;
	totalDays = y * 365 + y / 4 - y / 100 + y / 400 + DaysBeforeMonth[month - 1] + day;
	if (isLeapYear()&&month>2)
	{
		totalDays++;
	}
}
Date Date::read()
{
	int year, month, day;
	char c1, c2;
	cin >> year >> c1 >> month >> c2 >> day;
	return Date(year, month, day);
}

int Date::getMaxDay() const
{
	if (isLeapYear()&&month==2)
	{
		return 29;
	}
	else
	{
		return DaysBeforeMonth[month]-DaysBeforeMonth[month-1];
	}
}

void Date::show() const
{
	cout << getYear() << "-" << getMonth() << "-" << getDay() << "\t";
}
